import { pageBcpAndCp } from '@/api/materials/mesProdBom'
import { uniqueKey } from '@/utils/judge'
export const baseGoodsDialog = {
  data () {
    return {
      baseGoodsDialogVisible: false, //表格弹框隐藏显示
      pageBcpAndCp, // 获取弹框数据接口

      hasBaseGoodsFooter: true, // 是否需要底部按钮默认true
      baseGoodsSearchDialog: {
        inline: true,
        formDesc: {
          goodsCode: {
            type: 'input',
            layout: 8,
            label: $i18n.t('mesProdBom.materialCode')
          },
          goodsName: {
            type: 'input',
            layout: 8,
            label: $i18n.t('mesProdBom.materialName')
          }
        }
      },
      baseGoodsDialogColumn: [
        {
          type: 'selection',
          fixed: 'left'
        },
        {
          type: 'index',
          label: $i18n.t('common.order'),
          width: 60,
          fixed: 'left'
        },
        // {
        //   prop: "erpMaterialId",
        //   label: "erp物料id",
        // },
        {
          prop: 'goodsCode',
          label: $i18n.t('mesProdBom.materialCode'),
          width: 300,
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'goodsName',
          label: $i18n.t('mesProdBom.materialName'),
          width: 300,
          showOverflowTooltip: true
        },
        {
          prop: 'goodsDesc',
          label: $i18n.t('mesProdBom.materialDesc'),
          width: 300,
          showOverflowTooltip: true
        },
        {
          prop: 'goodsTypeKey',
          label: $i18n.t('mesProdBom.materialTypeCode'),
          width: 160,
          showOverflowTooltip: true
        },
        {
          prop: 'goodsTypeValue',
          label: $i18n.t('mesProdBom.materialTypeName'),
          width: 160,
          showOverflowTooltip: true
        },
        {
          prop: 'manufactureMethodValue',
          label: $i18n.t('mesProdBom.manufactureMethodCode'),
          width: 200,
          showOverflowTooltip: true
        },
        {
          prop: 'manufactureMethodName',
          label: $i18n.t('mesProdBom.manufactureMethodName'),
          width: 200,
          showOverflowTooltip: true
        },
        {
          prop: 'yardsSixNine',
          label: $i18n.t('mesProdBom.yardsSixNine'),
          width: 140,
          showOverflowTooltip: true
        },
        {
          prop: 'seriesCode',
          label: $i18n.t('mesProdBom.seriesCode'),
          width: 200,
          showOverflowTooltip: true
        },
        {
          prop: 'seriesName',
          label: $i18n.t('mesProdBom.seriesName'),
          width: 200,
          showOverflowTooltip: true
        },
        {
          prop: 'unit',
          label: $i18n.t('common.unit'),
          width: 100,
          showOverflowTooltip: true
        },
        {
          prop: 'unitCode',
          label: $i18n.t('common.unitCode'),
          width: 100,
          showOverflowTooltip: true
        },
        {
          prop: 'specification',
          label: $i18n.t('mesProdBom.specification'),
          width: 400,
          showOverflowTooltip: true
        },
        {
          prop: 'gbCode',
          label: $i18n.t('mesProdBom.gbCode'),
          width: 200,
          showOverflowTooltip: true
        }
      ]
    }
  },
  methods: {
    // async pageYCL() {
    //   let res = await pageYCL({
    //     excludeGoodsCode: this.formDataDialog.materialCode,
    //     ...this.$refs.tabledialog.formData,
    //   });
    //
    //   return res;
    // },

    // 弹框表格，双击表格，或者点击确定 返回选中数据
    getSelectBaseGoods (data) {
      // 调试完成记得删除控制台打印
      console.log('选中数据----', data)
      // 这里可以自定义返回字段信息
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      this.$set(this.formDataDialog, 'materialCode', data[0].goodsCode)
      this.$set(this.formDataDialog, 'materialName', data[0].goodsName)
      this.$set(this.formDataDialog, 'materialTypeValue', data[0].goodsTypeKey)
      this.$set(this.formDataDialog, 'materialTypeName', data[0].goodsTypeValue)
      this.$set(this.formDataDialog, 'unit', data[0].unit)
      this.$set(this.formDataDialog, 'unitCode', data[0].unitCode)
      this.$set(this.formDataDialog, 'manufactureMethodName', data[0].manufactureMethodName)
      this.$set(this.formDataDialog, 'manufactureMethodValue', data[0].manufactureMethodValue)
      this.$set(this.formDataDialog, 'serielsCode', data[0].seriesCode)
      this.$set(this.formDataDialog, 'serielsName', data[0].seriesName)
      this.$set(this.formDataDialog, 'quantity', data[0].layerQuantity)
      this.$set(this.formDataDialog, 'id', '')
    },

    getSelectBaseGoodsBoom (data) {
      let list = data.map((ite) => {
        return {
          // ...ite,
          materialCode: ite.goodsCode,
          materialName: ite.goodsName,
          unit: ite.unit,
          unitCode: ite.unitCode,
          manufactureMethodValue: ite.manufactureMethodValue,
          manufactureMethodName: ite.manufactureMethodName,
          materialTypeValue: ite.goodsTypeKey,
          materialTypeName: ite.goodsTypeValue,
          quantity: ite.layerQuantity,
          serielsName: ite.seriesName,
          serielsCode: ite.seriesCode,
          id: ''
        }
      })
      let arr = [...(this.formDataDialog.mesProdBomList || []), ...list]
      this.$set(this.formDataDialog, 'mesProdBomList', uniqueKey(arr, 'materialCode'))

      this.getBomVersionList(arr, 1)
    }
  }
}
